from django.db import models

# Create your models here.

class CaptionGroup(models.Model):
    '''部门表'''
    id = models.AutoField(primary_key=True)
    caption = models.CharField(max_length=10, null=False, unique=True)  # 部门名字为唯一值
    # ctime = models.DateTimeField(auto_now_add=True, null=True)
    # utime = models.DateTimeField(auto_now=True, null=True)

class LeverType(models.Model):
    '''职位级别的类别：如技术、行政等'''
    id = models.AutoField(primary_key=True)
    leveltype = models.CharField(max_length=10, unique=True)


class UserLevel(models.Model):
    '''职位级别表'''
    id = models.AutoField(primary_key=True)
    level = models.CharField(max_length=5, unique=True, null=False)
    user_level = models.ForeignKey('LeverType', to_field='id', default=1)


class UserGroup(models.Model):
    '''员工表'''
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=16, null=False)
    passwd = models.CharField(max_length=32, null=False)
    email = models.EmailField(max_length=50, null=True)
    tel = models.IntegerField(null=False)
    gender_type = ((1, '男'), (2, '女'))
    gender = models.IntegerField(choices=gender_type, default=1)
    user_caption = models.ForeignKey('CaptionGroup', to_field='id', default=1)  # 外键一对一关联，关联字段为uid，注意，关联的字段必须是主键！
    user_level = models.ForeignKey('UserLevel', to_field='id', default=1)

